package com.hss01248.dialog.bottomsheet;


import com.hss01248.dialog.ResourceTable;
import com.hss01248.dialog.ScreenUtil;
import com.hss01248.dialog.Tool;
import com.hss01248.dialog.adapter.SuperLvHolder;
import com.hss01248.dialog.config.BottomSheetStyle;
import ohos.agp.components.Component;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.Image;
import ohos.agp.components.Text;
import ohos.agp.components.Text.TextSizeType;
import ohos.app.Context;

/**
 * Created by Administrator on 2016/10/19.
 */

public class BsGvHolder extends SuperLvHolder<BottomSheetBean> {
    public Image ivIcon;
    public Text mTextView;

    public BsGvHolder(Context context){
        super(context);

    }

    @Override
    protected void findViews() {
        ivIcon = (Image) rootView.findComponentById(ResourceTable.Id_iv_icon);
        mTextView = (Text) rootView.findComponentById(ResourceTable.Id_tv_msg);
    }

    public void setStyle(BottomSheetStyle style){
        mTextView.setTextSize(style.txtSizeSp, TextSizeType.FP);
        Tool.setTextColorById(mTextView, style.txtColor);
        DirectionalLayout.LayoutConfig params = (DirectionalLayout.LayoutConfig) ivIcon.getLayoutConfig();
        if(params==null){
            params = new DirectionalLayout.LayoutConfig(DirectionalLayout.LayoutConfig.MATCH_PARENT,DirectionalLayout.LayoutConfig.MATCH_PARENT);
        }
        params.setMarginBottom(ScreenUtil.dip2px(style.txtMarginTopDp));
        params.setMarginsLeftAndRight(ScreenUtil.dip2px(style.gvItemMarginH)/2, ScreenUtil.dip2px(style.gvItemMarginH)/2);
        params.setMarginTop(ScreenUtil.dip2px(style.gvItemMarginV)/2);
        params.width = ScreenUtil.dip2px(style.iconSizeDp);
        params.height = ScreenUtil.dip2px(style.iconSizeDp);
        ivIcon.setLayoutConfig(params);

    }

    @Override
    protected int setLayoutRes() {
        return ResourceTable.Layout_item_bottomsheet_gv;
    }

    @Override
    public void assingDatasAndEvents(Context context, BottomSheetBean bean) {
        if (bean.icon<=0){
            ivIcon.setVisibility(Component.HIDE);
        }else {
            ivIcon.setPixelMap(bean.icon);
            ivIcon.setVisibility(Component.VISIBLE);
        }

        mTextView.setText(bean.text);
    }
}
